<template>
	<view class="admin-edit-device-detail-page">
		<titleName :name="name"></titleName>
		<view class="title-bgc"></view>
		<view class="content-wrap">
			<view class="sewage style-wrap">
				<view class="name"><text>*</text>二维码编号</view>
				<view class="val"><input type="text" disabled v-model="enterpriseMsg.devicecode" /></view>
			</view>
			<view class="enterprise-name style-wrap">
				<view class="name">
					<text>*</text>设施名称
				</view>
				<view class="val"><input type="text" v-model="enterpriseMsg.devicename" /></view>
			</view>
			<view class="session style-wrap">
				<view class="name"><text>*</text>涉废类型</view>
				<view class="val"><uni-data-select style="width: 100%;" placeholder="请选择"
						v-model="enterpriseMsg.devicetype" :localdata="adviceTypeList">
					</uni-data-select></view>
			</view>
			<view class="local-environmenta style-wrap">
				<view class="name"><text>*</text>设施状态</view>
				<view class="val"><uni-data-select style="width: 100%;" placeholder="状态" class="two"
						v-model="enterpriseMsg.status" :localdata="adviceStatusList" :clear="true"></uni-data-select>
				</view>
			</view>
			<view class="address style-wrap">
				<view class="name"><text>*</text>安装位置</view>
				<view class="val"><input type="text" v-model="enterpriseMsg.installposition" /></view>
			</view>
			<view class="address style-wrap">
				<view class="name"><text style="align-self: flex-start;">*</text>处理设计风量(m³/h)</view>
				<view class="val"><input type="text" v-model="enterpriseMsg.designairvolume" /></view>
			</view>
			<view class="address style-wrap">
				<view class="name"><text>*</text>设计使用量(kg)</view>
				<view class="val"><input type="text" v-model="enterpriseMsg.designusenum" /></view>
			</view>
			<view class="admin-one style-wrap">
				<view class="name"><text>*</text>更换周期(天)</view>
				<view class="val"><input type="text" v-model="enterpriseMsg.recircledays" /></view>
			</view>

			<!-- <view class="admin-two style-wrap">
				<view class="name"><text>*</text>环保管理员1</view>
				<view class="val"><input type="text" v-model="enterpriseMsg.hbperson" /></view>
			</view>
			<view class="admin-one style-wrap">
				<view class="name"><text>*</text>手机号</view>
				<view class="val"><input type="text" v-model="enterpriseMsg.hbmobile" /></view>
			</view>
			<view class="admin-two style-wrap">
				<view class="name"><text>*</text>环保管理员2</view>
				<view class="val"><input type="text" v-model="enterpriseMsg.hbpersonsecond" /></view>
			</view>
			<view class="admin-one style-wrap">
				<view class="name"><text>*</text>手机号</view>
				<view class="val"><input type="text" v-model="enterpriseMsg.hbmobilesecond" /></view>
			</view> -->

		</view>

		<view class="btn-wrap">
			<button @click="save">保存</button>
		</view>


	</view>
</template>

<script setup>
	import titleName from '../../components/titleName.vue'
	import http from '../../request/index'
	import uploadFile from '../../request/uploadFile.js'

	import {
		onShow,
		onLoad
	} from '@dcloudio/uni-app'
	import {
		reactive,
		ref,
		computed,
		nextTick
	} from 'vue'
	let name = '修改设施'
	let dataTree = ref([])
	let devicetypeValue = ref()
	let statusValue = ref()
	let adviceStatusList = ref([{}])
	let adviceTypeList = ref([])
	let agent = ref('')
	let enterpriseMsg = reactive({})
	let dischargeStyle = reactive({})

	onLoad((e) => {

		agent.value = e.agent
		// getSeleList()

		let msg = JSON.parse(e.msg)
		enterpriseMsg.devicecode = msg.devicecode
		enterpriseMsg.devicename = msg.devicename
		enterpriseMsg.devicetype = String(msg.devicetype)
		enterpriseMsg.status = String(msg.status)
		enterpriseMsg.installposition = msg.installposition
		enterpriseMsg.designairvolume = msg.designairvolume
		enterpriseMsg.designusenum = msg.designusenum
		enterpriseMsg.recircledays = msg.recircledays
		// enterpriseMsg.hbmobile = msg.hbmobile
		// enterpriseMsg.hbmobilesecond = msg.hbmobilesecond
		// enterpriseMsg.hbperson = msg.hbperson
		// enterpriseMsg.hbpersonsecond = msg.hbpersonsecond
		enterpriseMsg.id = msg.id






	})

	onShow(() => {

	})
	let getSeleList = () => {


	}
	http({
		url: '/listitem/getmodule',
		data: {
			module: 'B02'
		}
	}).then((res) => {
		if (res.code == 0) {
			let data = res.data
			adviceStatusList.value = data.map((item) => {
				return {
					text: item.name,
					value: item.id
				}


			})
		}

	})
	http({
		url: '/listitem/getmodule',
		data: {
			module: 'B03'
		}
	}).then((res) => {
		if (res.code == 0) {
			let data = res.data
			adviceTypeList.value = data.map((item) => {
				return {
					text: item.name,
					value: item.id
				}
			})


		}

	})
	let save = () => {
		// console.log(enterpriseMsg, 'enterpriseMsg');
		// let reg = /^1\d{10}$/
		// if (!reg.test(enterpriseMsg.hbmobile) || !reg.test(enterpriseMsg.hbmobilesecond)) {
		// 	uni.showToast({
		// 		title: '手机格式不正确',
		// 		icon: 'error',
		// 		mask: true
		// 	})
		// 	return
		// }

		for (let key in enterpriseMsg) {
			if (!enterpriseMsg[key]) {
				uni.showToast({
					title: "信息未填写完整",
					icon: 'error'
				})
				return
			}
		}

		http({
			url: '/device/addOrUpdateDevice',
			data: enterpriseMsg
		}).then((res) => {
			if (res.code == 0) {
				uni.showToast({
					title: '保存成功',
					icon: 'none',
					mask: true
				})
				setTimeout(() => {
					console.log(agent.value, 'agent');
					uni.redirectTo({
						url: `/contorllerPageOther/admineditdevicedetail/admineditdevicedetail?id=${enterpriseMsg.id}&agent=${agent.value}&type=2`
					})
				}, 1500)
			}

		})
	}
	let uploadImage = () => {

		uni.chooseImage({
			sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
			count: 1,
			success: function(res) {
				let tempFilePaths = res.tempFilePaths

				uploadFile({
					filePath: tempFilePaths[0]
				}).then((res) => {

					if (res.code == 0) {
						uni.getImageInfo({
							src: res.data.url,
							success: function(imageInfoRes) {

								dischargeStyle.width = imageInfoRes.width
								dischargeStyle.height = imageInfoRes.height
								console.log(dischargeStyle, 'dischargeStyle');

							}
						});
						enterpriseMsg.dischargelicenseurl = res.data.url
					}

				})


			}
		});

	}
</script>

<style lang="scss" scoped>
	:deep(.ipt-class) {

		font-weight: 400;
		font-size: 24rpx;
		color: #999999;


	}

	:deep(.selected-area) {
		padding-left: 0 !important;
		font-size: 26rpx !important;
	}

	:deep(.uni-select) {
		border: none !important;
		padding-left: 0;
	}

	:deep(.selected-area) {
		padding-left: 14rpx;
		font-weight: 400;
		font-size: 28rpx;
		color: #333333;

	}

	:deep(.uni-select__input-box) {
		padding-right: 5rpx;
	}

	:deep(.data-picker::placeholder) {
		color: red !important;
		padding-left: 30rpx;
	}

	:deep(.uni-icons.uniui-clear) {
		font-size: 22rpx;
	}

	:deep(.selected-list) {
		font-size: 28rpx;
		color: #333333;
		font-weight: 400;
	}

	:deep(.input-value) {
		padding: 0 !important;
	}

	:deep(.input-value-border) {
		border: none;
		height: 100%;
		padding-right: 25rpx;
	}

	:deep(.uni-data-tree) {
		padding-right: 5rpx;
	}

	:deep(.popper__arrow) {
		top: -6px;
		left: 50%;
		margin-right: 3px;
		border-top-width: 0;
		border-bottom-color: #EBEEF5;
	}

	:deep(.popper__arrow) {
		top: -6px;
		left: 50%;
		margin-right: 3px;
		border-top-width: 0;
		border-bottom-color: #EBEEF5;
	}

	:deep(.uni-select__input-text) {

		font-weight: 400 !important;
		font-size: 28rpx !important;
		color: #333333 !important;

	}

	.admin-edit-device-detail-page {
		width: 100vw;
		height: 100vh;


		.title-bgc {
			width: 750rpx;
			height: 160rpx;
			background: #0874FA;
		}

		.btn-wrap {
			margin-top: 70rpx;
			padding-bottom: 65rpx;

			button {
				margin: 0 auto;
				width: 672rpx;
				height: 88rpx;
				background: #0874FA;
				border-radius: 44rpx;

				font-weight: 500;
				font-size: 31rpx;
				color: #FFFFFF;
				line-height: 88rpx;
			}
		}

		.business-license,
		.sewage-discharge {
			// margin-top: 20rpx;
			padding-bottom: 20rpx;

			.name {

				font-size: 30rpx;
				color: #000;
				line-height: 33rpx;
				padding-left: 30rpx;
				height: 85rpx;
				line-height: 85rpx;
				width: auto !important;

				text {
					color: #F82A24;
				}

			}

			.val {
				width: 100vw;
				padding: 0 30rpx 0 26rpx;
				margin-top: 10rpx;

				.wrap {
					min-height: 376rpx;
					background: #FFFFFF;
					border-radius: 14rpx;
					border: 1px dashed #BFBFBF;
					display: flex;
					justify-content: center;
					align-items: center;
					flex-direction: column;
					overflow: hidden;

					image {
						width: 304rpx;
						height: 235rpx;

					}
				}

				.btm {
					margin-top: 36rpx;
					display: flex;
					align-items: center;

					image {
						width: 36rpx;
						height: 29rpx;
						margin-right: 15rpx;
					}

					text,
					button {

						font-weight: 400;
						font-size: 28rpx;
						color: #CBCDD5;


					}
				}
			}
		}

		.content-wrap {
			padding-top: 20rpx;

			.style-wrap {
				padding-left: 30rpx !important;
				padding-right: 28rpx !important;

				.name {
					display: flex;
					justify-content: flex-start;
					width: 250rpx;
					font-weight: 400 !important;
					font-size: 31rpx !important;
					color: #000000 !important;

					text {
						color: #F82A24 !important;
					}
				}

				.val {
					width: 491rpx;
					height: 59rpx;
					background: #FAFAFA;
					border-radius: 7rpx;
					border: 1px solid #BFBFBF;
					padding-left: 30rpx;

					input {
						width: 100%;
						font-weight: 400;
						font-size: 26rpx;
						color: #333333;

					}
				}
			}

			view {
				display: flex;
				justify-content: space-between;
				height: 85rpx;
				padding: 48rpx 45rpx 45rpx 45rpx;
				align-items: center;

				.name {

					font-weight: 400;
					font-size: 31rpx;
					color: #666666;

					padding: 0;
				}

				.val {

					font-weight: 400;
					font-size: 33rpx;
					color: #333333;
					padding: 0;
				}
			}
		}
	}
</style>